package com.cdream.basic.algorithm.leetcode.string;

/**
 * @author cdream
 * @date 2022/2/1
 */
public class Question1763 {

    public String longestNiceSubstring(String s) {
        int max = 0;
        int length = 0;
        for(int i = 0; i<s.length();i++){
            int l = 0;
            int h = 0;
            for(int j = i; j<s.length();j++){
                char c = s.charAt(j);
                if(c<='Z'){
                    h |= 1<<(c-'A');
                }else {
                    l |= 1<<(c-'a');
                }
                if(l==h && (j-i+1)>length){
                    max = i;
                    length = j-i+1;
                }
            }
        }
        return s.substring(max,max+length);
    }

    public static void main(String[] args) {
        new Question1763().longestNiceSubstring("YazaAay");
    }
}
